import time


def timeit(get_response):
    """中间件函数：记录请求花费时间"""
    def middleware(request):
        start = time.time()
        print(
            f"{time.asctime()} 收到 { request.method} 请求，URL: { request.get_full_path()}")
        response = get_response(request)  # 此步进入View函数
        end = time.time()
        print(f"{time.asctime()} view处理完请求")
        print(f"处理请求花费时间:{(end-start):.6f}s")
        return response

    return middleware
